﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.Core.Specification;
using Domain.MainModule.Entities;

namespace Domain.MainModule.GroupBranches
{
    public class GroupBranchNamePrioritySpecification: Specification<GroupBranch>
    {
        private string _Name = string.Empty;
        private int? _Priority = null;

        public GroupBranchNamePrioritySpecification(string name)
        {
            this._Name = name;
        }

        public GroupBranchNamePrioritySpecification(string name, int? priority)
        {
            this._Name = name;
            this._Priority = priority;
        }

        public override System.Linq.Expressions.Expression<Func<GroupBranch, bool>> SatisfiedBy()
        {
            Specification<GroupBranch> spec = new TrueSpecification<GroupBranch>();

            spec &= new DirectSpecification<GroupBranch>(c => !string.IsNullOrEmpty(_Name)  && c.Name.Contains(_Name));

            if (this._Priority.HasValue)
            {
                spec &= new DirectSpecification<GroupBranch>(c => c.Priority == this._Priority);
            }

            return spec.SatisfiedBy();

        }
    }
}
